/* eslint-disable */
import { createApp } from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'
import installElementPlus from './plugins/element.js'
import markdownit from './plugins/markdownIt'
import cookies from 'vue-cookies'
import qs from 'qs'
import axios from 'axios'
import prism from './static/js/prism'
import 'github-markdown-css'


cookies.config('30d',store.getters.getPathPrefix());

axios.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded';
axios.defaults.withCredentials = true;

router.beforeEach((to, from, next) => {
  store.commit("setBackgroundTop",0);
  store.commit("setBackgroundLeft",0);
  if(to.meta.requiresLogin) {
    var url = store.getters.getPathPrefix() + to.name + "/permission-test";
    axios.get(url).then(response => {
      if(response.data.flg) {
        next();
      } else {
        next({name : "login"});
      }
    });
  }
  else next();
})


const app = createApp(App)
app.use(store);
app.use(router);
installElementPlus(app);

app.config.globalProperties.productionTip = false;
app.config.globalProperties.$qs = qs;
app.config.globalProperties.$axios = axios;
app.config.globalProperties.$cookies = cookies;
app.config.globalProperties.$prism = prism;
app.config.globalProperties.$MarkdownRender = (src) => { return markdownit.render(src) };

app.mount('#app')

